<?php
	require_once("utils.php");
	require_once("obj/role.php");
	require_once("obj/report.php");
	$session = Session::getFromURL();
	$sid = "";
	$role = "";
	if($session != null){
		if($session->isAlive()) {
			$sid = $session->SID;
			$roleobj = Role::getBySession($sid);
			$role = $roleobj == null ? "" : $roleobj->Name;
		}
	}
	// find what reports are available for this role
	$reports = Report::getForReportsForRole($roleobj->RoleId);
?>

<form method="post" action="<?php echo Utils::makeReportDetailUrl($reports->ReportId);?>">
<table class="datatable" width="100%" cellpadding="5" cellspacing="0">
<tr><th>Name</th><th>Description</th><th>&nbsp;</th><th>&nbsp;</th><th>&nbsp;</th></tr>
<?php
	// generate table with an entry for each available report.
	$ix = 0;
	foreach($reports as $r){
		$i = $r->ReportId;
		$n = $r->Name;
		$d = $r->Description;
		$u = Utils::makeReportDetailUrl($i);
		$cs = $ix % 2 == 0 ? "row" : "altrow";
		if($i == MONTLY_USER_TOTALS)
		{
			echo "<tr class=\"$cs\"><td>$n</a></td><td>$d</td><td>
				<select id=\"selMonth\" name=\"selMonth\">
					<option value=\"1\" selected = \"selected\">January</option>
					<option value=\"2\">February</option>
					<option value=\"3\">March</option>
					<option value=\"4\">April</option>
					<option value=\"5\">May</option>
					<option value=\"6\">June</option>
					<option value=\"7\">July</option>
					<option value=\"8\">August</option>
					<option value=\"9\">September</option>
					<option value=\"10\">October</option>
					<option value=\"11\">November</option>
					<option value=\"12\">December</option>
				</select></td><td>&nbsp</td><td><input type=\"submit\" value=\"Generate\"></td></tr>";
		}	
		else if($i == MGR_SLCT_USR_TTLS)
		{
			echo "<tr class=\"$cs\"><td>$n</a></td><td>$d</td><td>
			<td><input id=\"txtEmail\" name=\"txtEmail\" type=\"text\" value=\"\" /></td><td><input type=\"submit\" value=\"Generate\"></td></tr>";
		}
		else
		{
			echo "<tr class=\"$cs\"><td>$n</a></td><td>$d</td><td>&nbsp</td><td>&nbsp</td><td><form><input type=\"button\" value=\"Generate\" onCLick=\"window.location.href='$u'\"></form></td></tr>";
		}
		$ix++;
	}
?>
</table>
</form>
